local Stamina = Class(function(self, inst)
    self.inst = inst

    local classified = inst.player_classified
    if TheWorld.ismastersim then
        self.classified = classified
    elseif classified and self.classified == nil then
        self:AttachClassified(classified)
    end
end)

function Stamina:AttachClassified(classified)
    self.classified = classified
    self.ondetachclassified = function() self:DetachClassified() end
    self.inst:ListenForEvent("onremove", self.ondetachclassified, classified)
end

function Stamina:DetachClassified()
    self.classified = nil
    self.ondetachclassified = nil
end

function Stamina:SetCurrent(current)
    if self.classified ~= nil then
        self.classified:SetValue("assn_stamina_current", current)
    end
end

function Stamina:SetMax(max)
    if self.classified ~= nil then
        self.classified:SetValue("assn_stamina_max", max)
    end
end

function Stamina:GetCurrent()
    if self.inst.components.stamina ~= nil then
        return self.inst.components.stamina.current
    elseif self.classified ~= nil then
        return self.classified.assn_stamina_current:value()
    else
        return 0
    end
end

function Stamina:GetMax()
    if self.inst.components.stamina ~= nil then
        return self.inst.components.stamina.max
    elseif self.classified ~= nil then
        return self.classified.assn_stamina_max:value()
    else
        return 0
    end
end

return Stamina
